<!DOCTYPE html>
<html>
<head>
    <title>管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-inline" id="positionListBox">
                        	<input type="text" name="title" placeholder="搜索标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <#if shiro.hasPermission("mengmao:hcslide:save")>
        <button class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加 </button>
        </#if>
    </div>
</script>

<script type="text/html" id="currentTableTypeTpl">
    {{# if(d.type == 1){ }}
    <span class="layui-badge layui-bg-green">轮播图</span>
    {{# } else if(d.type == 0){ }}
    <span class="layui-badge layui-bg-green">通知</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">启用</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-grey">禁用</span>
    {{# } }}
</script>
<script type="text/html" id="img">
	<div><a href="http://localhost:8089/admin/asset/gettu?name={{d.image}}" target="_blank"><img src="http://localhost:8089/admin/asset/gettu?name={{d.image}}" class="layui-nav-img" style="width:20px;height:20px"></a></div>
</script>
<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("mengmao:hcslide:save")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </#if>
    <#if shiro.hasPermission("mengmao:hcslide:delete")>
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </#if>
</script>

<script id="positionListTpl" type="text/html">
    <select name="position">
        <option value="">选择位置</option>
        {{#  layui.each(d, function(index, item){ }}
        <option value="{{item.value}}">{{item.name}}</option>
        {{#  }); }}
    </select>
</script>
<script type="text/javascript">
    var formDataId = 0;
    var positionList = [];
    var _parent = parent;
    layui.use(['form', 'table', 'laytpl'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laytpl = layui.laytpl;

       /*  $.ajax({
            type: "POST",
            url: serverUrl('ads/positions'),
            data: {},
            dataType: "json",
            success: function (result) {
                positionList = result.list;
                laytpl($("#positionListTpl").html()).render(positionList, function(html){
                    $("#positionListBox").html(html);
                    form.render("select");
                });
            }
        }); */
        tableSearch({},'slideitem/list?id='+parent.formDataId);
        
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter'],
                cols: [[
                    {type: "numbers", width: 50},
                    {field: 'status', title: 'status', minWidth: 140 },
                    {field: 'listOrder', title: 'listOrder', minWidth: 140 },
                    {field: 'title', title: 'title', minWidth: 140 },
                    {field: 'image', title: '图片', minWidth: 70 ,  templet: '#img'},
                    {field: 'url', title: 'url', minWidth: 140 },
                    {field: 'description', title: '描述', minWidth: 140 },
                    {field: 'content', title: 'content', minWidth: 140 },
                    {title: '操作', width: 150, toolbar: '#currentTableBar', align: "center"}

                ]],
                limits: [15, 30, 50],
                limit: 15,
                page: true
            });
        	return tablethis;
        };
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                formDataId = 0;
            	sid=parent.formDataId;
                openFormView('app/HcSlideItem/form.html', '添加');

            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/HcSlideItem/form.html', '编辑');
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确定删除吗？', function (index) {
                    deleteTableRow('slideitem/delete', [data.id], function (rs) {
                        obj.del();
                    });
                    layer.close(index);
                });
            }
        });

        // 监听搜索操作
        form.on('submit(form-search-btn)', function (data) {
            //执行搜索重载
            if (data.field.title) {
            	tableSearch({"title":data.field.title},'slideitem/search');
            //table.filterData(data.field.title);
	        } else {
	            table.clearFilter();
	        }
	        return false;
	    });
        form.on('submit(form-reset-btn)', function (data) {
        	tableSearch({},'navmenu/list');
            $("#searchForm")[0].reset();
            table.clearFilter();
            return false;
        });

    });
</script>

</body>
</html>